package com.qdsgjsfk.vision.ui.fragment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.view.OptionsPickerView;
import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleNotifyCallback;
import com.clj.fastble.callback.BleWriteCallback;
import com.clj.fastble.exception.BleException;
import com.qdsgjsfk.vision.R;
import com.qdsgjsfk.vision.base.BaseApplication;
import com.qdsgjsfk.vision.base.BaseFragment;
import com.qdsgjsfk.vision.eventbus.AxisBlueData;
import com.qdsgjsfk.vision.eventbus.BlueTooth;
import com.qdsgjsfk.vision.eventbus.Clear;
import com.qdsgjsfk.vision.eventbus.StartVision;
import com.qdsgjsfk.vision.service.SocketService;
import com.qdsgjsfk.vision.ui.DeviceTypeActivity;
import com.qdsgjsfk.vision.ui.dialog.QualifiedDialog;
import com.qdsgjsfk.vision.ui.dialog.RemarkDialog;
import com.qdsgjsfk.vision.util.Constant;
import com.qdsgjsfk.vision.util.DiopterDataUtil;
import com.qdsgjsfk.vision.util.NetUtil;
import com.qdsgjsfk.vision.util.ToastUtil;
import com.qdsgjsfk.vision.util.UtilString;
import com.rest.business.RestProxy;
import com.rest.response.AxisResponse;
import com.rest.response.QualifiedResponse;
import com.rest.response.StudentInfoResponse;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import jz.joyoung.robot.util.LogUtil;
import util.PreferencesHelper;
import util.UtilList;

/**
 * 眼轴页面
 * Created by lbj on 2022/10/9 13:56
 */

public class AxisFragment extends BaseFragment {


    @BindView(R.id.tv_ble_test)
    TextView tvBleTest;
    @BindView(R.id.stuName)
    TextView stuName;
    @BindView(R.id.btn_connect_device)
    LinearLayout btnConnectDevice;

    @BindView(R.id.tv_remark)
    TextView tvRemark;
    @BindView(R.id.more)
    ImageView more;
    @BindView(R.id.btn_remark)
    LinearLayout btnRemark;
    @BindView(R.id.tv_examiner)
    TextView tvExaminer;
    @BindView(R.id.tv_examiner_time)
    TextView tvExaminerTime;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.tv_vision)
    TextView tvVision;
    @BindView(R.id.btn_confirm)
    TextView btnConfirm;
    @BindView(R.id.ll_bottom)
    LinearLayout llBottom;
    @BindView(R.id.odAl)
    EditText odAl;
    @BindView(R.id.osAl)
    EditText osAl;
    @BindView(R.id.odVar)
    EditText odVar;
    @BindView(R.id.osVar)
    EditText osVar;
    @BindView(R.id.odK1)
    EditText odK1;
    @BindView(R.id.osK1)
    EditText osK1;
    @BindView(R.id.odK2)
    EditText odK2;
    @BindView(R.id.osK2)
    EditText osK2;
    @BindView(R.id.odAvgk)
    EditText odAvgk;
    @BindView(R.id.osAvgk)
    EditText osAvgk;
    @BindView(R.id.odAlav)
    EditText odAlav;
    @BindView(R.id.osAlav)
    EditText osAlav;
    private InputStream mmInStream;
    private OutputStream mmOutStream;
    String studentId, taskId, blueData = "", strName = null, strAddress = null, manual = "0";
    TextView currentView;
    private QualifiedDialog mQualifiedDialog;
    private RemarkDialog mRemarkDialog;
    ProgressDialog progressDialog;
    OptionsPickerView pvOptions_zhujing, pvOptions_qiujing;
    List<String> options1Items = new ArrayList<>();
    List<String> options3Items = new ArrayList<String>();

    List<String> options2Items = new ArrayList<>();
    private boolean isCanSave = false;
    Activity activity;
    private boolean isEmptyRemark = true;
    private String brand, software_version, Id, studentName, stuSex, stuBirth;

    private int bleCount = 0;
    Unbinder unbinder;

    /**
     * EventBus传值
     */
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEvent(AxisBlueData event) {

        if (event.type == Constant.BLUE_AXL_800) {
            DiopterDataUtil.setAXL800( event.output, odAl, odVar, odK1, odK2, odAvgk, odAlav, osAl, osVar, osK1, osK2, osAvgk, osAlav );
            changeBottomSave();
            EventBus.getDefault().postSticky( new Clear( 1 ) );
        }

    }

    /**
     * 更新蓝牙数据
     *
     * @time 2020/12/1 15:07
     */
    private void notifyBLE(String uuid_service, String uuid_notify) throws JSONException {
        if (BaseApplication.currentBleDevice == null)
            return;
        if (bleCount >= 3) {
            ToastUtil.showToastCenter( mContext, "蓝牙断开连接，请重新连接" );
            return;
        }

        BleManager.getInstance().notify(
                BaseApplication.currentBleDevice,
                uuid_service,
                uuid_notify,
                new BleNotifyCallback() {
                    @Override
                    public void onNotifySuccess() {// 打开通知操作成功
                        LogUtil.e( "眼轴蓝牙读取---" + "眼轴打开通知操作成功" );
                        if (!BaseApplication.strName.contains( "VisionScreener" )) {
                            BleManager.getInstance().getBluetoothGatt( BaseApplication.currentBleDevice ).requestMtu( 512 );
                        }
                    }

                    @Override
                    public void onNotifyFailure(BleException exception) { // 打开通知操作失败
                        bleCount++;
                        ToastUtil.showToastCenter( mContext, "蓝牙重新读取中..." );
                        if (BaseApplication.strName.contains( "AXL-800" ) || BaseApplication.strName.contains( "WH-BLE" )) {
                            try {
                                notifyBLE( "0003CDD0-0000-1000-8000-00805F9B0131", "0003CDD1-0000-1000-8000-00805F9B0131" );
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        LogUtil.e( "眼轴蓝牙读取---" + "眼轴打开通知操作失败" + "---" + bleCount );

                    }

                    @Override
                    public void onCharacteristicChanged(byte[] data) {// 打开通知后，设备发过来的数据将在这里出现
                        String dataChanged = new String( data );
                        Log.e( "dataChanged---", dataChanged );
                        if (BaseApplication.strName.contains( "VisionScreener" )) {
                            blueData = new String( data );
                        } else {
                            blueData = blueData + new String( data );
                        }
                        if ((BaseApplication.strName.contains( "AXL-800" ) || BaseApplication.strName.contains( "WH-BLE" )) && blueData.startsWith( "<OD/R>: AL-" )) { //雄博AXL-800设备
                            if (!UtilString.isEmpty( blueData )) {
                                Log.e( "雄博AXL-800蓝牙---", blueData );
                                List<String> list = new ArrayList<>( Arrays.asList( blueData.split( "\\|\\|" ) ) );
                                Log.e( "雄博AXL-800蓝牙长度", String.valueOf( list.size() ) );
                                if (list.size() == 13) {
                                    LogUtil.e( "眼轴长度" + list.size() );
                                    DiopterDataUtil.setAXL800( blueData, odAl, odVar, odK1, odK2, odAvgk, odAlav, osAl, osVar, osK1, osK2, osAvgk, osAlav );
                                    changeBottomSave();

                                    new Handler().postDelayed( () -> {
                                        blueData = "";
//                                    EventBus.getDefault().postSticky( new AxisBlueData( blueData, Constant.BLUE_AXL_800 ) );
                                    }, 1000 );
                                } else if (list.size() == 11 && !blueData.contains( "AST" )) {
                                    DiopterDataUtil.setAXL800( blueData, odAl, odVar, odK1, odK2, odAvgk, odAlav, osAl, osVar, osK1, osK2, osAvgk, osAlav );
                                    changeBottomSave();
                                    new Handler().postDelayed( () -> {
                                        blueData = "";
                                    }, 1000 );
                                }

                            }

                        }
                    }
                } );
    }


    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_axis;
    }

    @Override
    protected void initView() {
        progressDialog = new ProgressDialog( activity );
        progressDialog.setCancelable( false );
        progressDialog.setMessage( "数据上传中..." );

        odAl.addTextChangedListener( new Watcher( odAl ) );
        osAl.addTextChangedListener( new Watcher( osAl ) );
        odVar.addTextChangedListener( new Watcher( odVar ) );
        osVar.addTextChangedListener( new Watcher( osVar ) );
        odK1.addTextChangedListener( new Watcher( odK1 ) );
        osK1.addTextChangedListener( new Watcher( osK1 ) );
        odK2.addTextChangedListener( new Watcher( odK2 ) );
        osK2.addTextChangedListener( new Watcher( osK2 ) );
        odAvgk.addTextChangedListener( new Watcher( odAvgk ) );
        osAvgk.addTextChangedListener( new Watcher( osAvgk ) );
        odAlav.addTextChangedListener( new Watcher( odAlav ) );
        osAlav.addTextChangedListener( new Watcher( osAlav ) );
//
//        //轴位监听
//        odAxial.addTextChangedListener( new WatcherZW( odAxial, tvOdAxial ) );
//        osAxial.addTextChangedListener( new WatcherZW( osAxial, tvoSAxial ) );


        refreshLayout.setPrimaryColors( 0xffffffff, 0xff55B8A9 );
        refreshLayout.setEnableLoadMore( false );
        refreshLayout.setOnRefreshListener( refreshLayout -> {
            mContext.stopService( new Intent( mContext, SocketService.class ) );
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                mContext.startForegroundService( new Intent( mContext, SocketService.class ) );
            } else {
                mContext.startService( new Intent( mContext, SocketService.class ) );
            }
            getEyeVisionByBiology();
            new Handler().postDelayed( () -> refreshLayout.finishRefresh( true ), 1000 );
        } );


    }

    @Override
    protected void initData() {
        if (!EventBus.getDefault().isRegistered( this )) {
            EventBus.getDefault().register( this );
        }
        strName = BaseApplication.strName;
        strAddress = BaseApplication.strAddress;
        assert getArguments() != null;
        studentId = getArguments().getString( "studentId" );
        taskId = getArguments().getString( "taskId" );

    }


    @OnClick(R.id.btn_connect_device)
    void btn_connect_device() {
        startActivity( DeviceTypeActivity.class );
    }


    @OnClick(R.id.btn_confirm)
    void btn_confirm() {
        String remark = "";
        if (TextUtils.isEmpty( odAl.getText().toString() ) || TextUtils.isEmpty( osAl.getText().toString() ) || TextUtils.isEmpty( odAvgk.getText().toString() ) || TextUtils.isEmpty( osAvgk.getText().toString() ) || TextUtils.isEmpty( odAlav.getText().toString() ) || TextUtils.isEmpty( osAlav.getText().toString() )) {
            if (isEmptyRemark) {
                Toast.makeText( activity, "请填写眼轴长,平均曲率,轴率比数据或者备注", Toast.LENGTH_SHORT ).show();
            } else {
                remark = tvRemark.getText().toString().trim();
                requestInterface( remark );
            }
        } else {
            if (!isEmptyRemark) {
                remark = tvRemark.getText().toString().trim();
            }
            requestInterface( remark );


        }
    }


    @Override
    public void onStart() {
        super.onStart();
        getEyeVisionByBiology();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint( isVisibleToUser );
        LogUtil.e( "setUserVisibleHint---", isVisibleToUser + "---AxisFragment--" + getUserVisibleHint() );
        if (isVisibleToUser) {
            if (BaseApplication.currentBleDevice == null)
                return;
            bleCount = 0;
            LogUtil.e( "strName----" + BaseApplication.strName );
            if (BaseApplication.strName.contains( "AXL-800" ) || BaseApplication.strName.contains( "WH-BLE" )) {
                LogUtil.e( "连接蓝牙的" + BaseApplication.strName );//AXL-800眼轴测力仪
                try {
                    notifyBLE( "0003CDD0-0000-1000-8000-00805F9B0131", "0003CDD1-0000-1000-8000-00805F9B0131" );
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated( view, savedInstanceState );
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach( context );
        activity = (Activity) context;//保存Context引用
    }


    @Override
    public void onDestroy() {
//        activity.unregisterReceiver(connectDevices);
        EventBus.getDefault().unregister( this );
        super.onDestroy();
    }

    @Override
    public void onPause() {
        super.onPause();
        LogUtil.e( "AxisFragment---", "onPause" );
    }

    @Override
    public void onStop() {
        super.onStop();
        LogUtil.e( "AxisFragment---", "onStop" );
    }


    private void getEyeVisionByBiology() {
        RestProxy.getInstance().getEyeVisionByBiology( studentId + "", taskId, new Observer<AxisResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AxisResponse axisResponse) {
                try {
//                    BaseApplication.currentEditId = studentInfoResponse.data.id;
                    odAl.setText( axisResponse.data.odAl == null ? "" : axisResponse.data.odAl );
                    osAl.setText( axisResponse.data.osAl == null ? "" : axisResponse.data.osAl );
                    odVar.setText( axisResponse.data.odVar == null ? "" : axisResponse.data.odVar );
                    osVar.setText( axisResponse.data.osVar == null ? "" : axisResponse.data.osVar );
                    odK1.setText( axisResponse.data.odK1 == null ? "" : axisResponse.data.odK1 );
                    osK1.setText( axisResponse.data.osK1 == null ? "" : axisResponse.data.osK1 );
                    odK2.setText( axisResponse.data.odK2 == null ? "" : axisResponse.data.odK2 );
                    osK2.setText( axisResponse.data.osK2 == null ? "" : axisResponse.data.osK2 );
                    odAvgk.setText( axisResponse.data.odAvgk == null ? "" : axisResponse.data.odAvgk );
                    osAvgk.setText( axisResponse.data.osAvgk == null ? "" : axisResponse.data.osAvgk );
                    odAlav.setText( axisResponse.data.odAlAvgk == null ? "" : axisResponse.data.odAlAvgk );
                    osAlav.setText( axisResponse.data.osAlAvgk == null ? "" : axisResponse.data.osAlAvgk );

                    tvExaminer.setText( String.format( "检查人:%s", axisResponse.data.checker == null ? "" : axisResponse.data.checker ) );
                    tvExaminerTime.setText( String.format( "检查时间:%s", axisResponse.data.createTime ) );


                    if (!TextUtils.isEmpty( axisResponse.data.remark )) {

                        tvRemark.setTextColor( ContextCompat.getColor( activity, R.color.lightBlack ) );
                        tvRemark.setText( axisResponse.data.remark );
                        isEmptyRemark = false;
                    } else {
                        isEmptyRemark = true;
                    }
                    changeBottomSave();
                } catch (Exception e) {
                    e.printStackTrace();
                    activity.runOnUiThread( () -> Toast.makeText( activity, "服务器数据异常", Toast.LENGTH_SHORT ).show() );
                }
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                NetUtil.onError( e, activity );
            }

            @Override
            public void onComplete() {

            }
        } );
    }


    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEvent(Clear clear) {
        if (clear.clear == 1) {
            blueData = "";
        }
    }

    //屈光度异常弹窗

    private void showQualifiedDialog() {
//        if (mQualifiedDialog == null) {
        mQualifiedDialog = QualifiedDialog.newInstance( "屈光与视力不匹配，建议重新检查" );
        mQualifiedDialog.show( getChildFragmentManager(), "mQualifiedDialog" );
        mQualifiedDialog.setmListener( new QualifiedDialog.OnItemClickListener() {

            @Override
            public void onConfirm() {
                mQualifiedDialog.dismiss();
            }

            @Override
            public void onCancel() {
                activity.finish();
            }
        } );
    }

    @OnClick(R.id.btn_remark)
    void btn_remark() {
        showRemarkDialog();
    }

    /**
     * 备注弹窗
     *
     * @time 2020/5/27 9:17
     */
    private void showRemarkDialog() {
        if (mRemarkDialog == null) {
            mRemarkDialog = RemarkDialog.newInstance( true, false );
            mRemarkDialog.show( getChildFragmentManager(), "mRemarkDialog" );
            mRemarkDialog.setmListener( (reason, type) -> {

                if (!UtilString.isEmpty( reason )) {
                    isEmptyRemark = false;
                    tvRemark.setTextColor( ContextCompat.getColor( activity, R.color.lightBlack ) );
                    tvRemark.setText( reason );
                    changeBottomSave();
                } else {
                    //清空
                    isEmptyRemark = true;
                    tvRemark.setTextColor( ContextCompat.getColor( activity, R.color.ffd3dcdc ) );
                    tvRemark.setText( "备注：无检测数据必填，否则视为未筛查" );
                    changeBottomSave();
                }

                mRemarkDialog.dismiss();
            } );
        } else if (!mRemarkDialog.isAdded() && !mRemarkDialog.isShowing()) {
            mRemarkDialog.show( getChildFragmentManager(), "mRemarkDialog" );
        }
    }


    private void requestInterface(String remark) {
        String ygyDevice = PreferencesHelper.getInstance().getString( activity, "ygyDevice" );
        LogUtil.e( "ygy设备类型----", ygyDevice );
        Map<String, Object> map = new HashMap<>();//body  map
        map.put( "studentId", studentId + "" );
        map.put( "odAl", odAl.getText().toString().trim() );
        map.put( "osAl", osAl.getText().toString().trim() );
        map.put( "odVar", odVar.getText().toString().trim() );
        map.put( "osVar", osVar.getText().toString().trim() );
        map.put( "odK1", odK1.getText().toString().trim() );
        map.put( "osK1", osK1.getText().toString().trim() );
        map.put( "odK2", odK2.getText().toString().trim() );
        map.put( "osK2", osK2.getText().toString().trim() );
        map.put( "odAvgk", odAvgk.getText().toString().trim() );
        map.put( "osAvgk", osAvgk.getText().toString().trim() );
        map.put( "odAlAvgk", odAlav.getText().toString().trim() );
        map.put( "osAlAvgk", osAlav.getText().toString().trim() );
        map.put( "taskId", taskId );
        map.put( "remark", remark );
        map.put( "collectSource", "0" );
        map.put( "softwareVersion", software_version );
        map.put( "autoRefractorId", Id );
        map.put( "deviceName", ygyDevice );
        RestProxy.getInstance().addEyeVisionDataByBiology( map, new Observer<QualifiedResponse>() {
            @Override
            public void onSubscribe(Disposable d) {
//                    btn_confirm.setClickable( false );
                progressDialog.show();
            }

            @Override
            public void onNext(QualifiedResponse qualifiedResponse) {
                if (AxisFragment.this.isAdded()) {
                    progressDialog.dismiss();
                }
                if (qualifiedResponse.data) {
                    showQualifiedDialog();
                } else {
                    Toast.makeText( activity, "保存成功", Toast.LENGTH_SHORT ).show();
                    activity.finish();

                }
            }

            @Override
            public void onError(Throwable e) {
                progressDialog.dismiss();
                NetUtil.onError( e, activity );
//                    btn_confirm.setClickable( true );
            }

            @Override
            public void onComplete() {
//                    btn_confirm.setClickable( true );
            }
        } );

    }


    @OnClick({R.id.odAl, R.id.osAl, R.id.odVar, R.id.osVar, R.id.odK1, R.id.osK1, R.id.odK2, R.id.osK2, R.id.odAvgk, R.id.osAvgk, R.id.odAlav, R.id.osAlav})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.odAl:
                requestFocus( odAl );
                break;
            case R.id.osAl:
                requestFocus( osAl );
                break;
            case R.id.odVar:
                requestFocus( odVar );
                break;
            case R.id.osVar:
                requestFocus( osVar );
                break;
            case R.id.odK1:
                requestFocus( odK1 );
                break;
            case R.id.osK1:
                requestFocus( osK1 );
                break;
            case R.id.odK2:
                requestFocus( odK2 );
                break;
            case R.id.osK2:
                requestFocus( osK2 );
                break;
            case R.id.odAvgk:
                requestFocus( odAvgk );
                break;
            case R.id.osAvgk:
                requestFocus( osAvgk );
                break;
            case R.id.odAlav:
                requestFocus( odAlav );
                break;
            case R.id.osAlav:
                requestFocus( osAlav );
                break;
        }
    }

    class Watcher implements TextWatcher {

        EditText etTextView;
        TextView textView;
        double start, end;

        Watcher(EditText odR1mm) {
            this.etTextView = odR1mm;
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String trim = etTextView.getText().toString().trim();

            if (!UtilString.isEmpty( trim )) {
                changeBottomSave();
            }

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {


        }


    }


    void changeBottomSave() {
        if (!isEmptyRemark) {
            //备注不为空
            btnConfirm.setBackground( ContextCompat.getDrawable( activity, R.drawable.item_bg_blue_button ) );
            btnConfirm.setTextColor( ContextCompat.getColor( activity, R.color.white ) );
        } else {
            if (TextUtils.isEmpty( odAl.getText().toString() ) || TextUtils.isEmpty( osAl.getText().toString() ) || TextUtils.isEmpty( odAvgk.getText().toString() ) || TextUtils.isEmpty( osAvgk.getText().toString() ) || TextUtils.isEmpty( odAlav.getText().toString() ) || TextUtils.isEmpty( osAlav.getText().toString() )) {
                btnConfirm.setBackground( ContextCompat.getDrawable( activity, R.drawable.item_bg_light_blue_button ) );
                btnConfirm.setTextColor( ContextCompat.getColor( activity, R.color.white ) );
            } else {
                btnConfirm.setBackground( ContextCompat.getDrawable( activity, R.drawable.item_bg_blue_button ) );
                btnConfirm.setTextColor( ContextCompat.getColor( activity, R.color.white ) );
            }
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView( inflater, container, savedInstanceState );
        assert rootView != null;
        unbinder = ButterKnife.bind( this, rootView );
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    public static AxisFragment newInstance(String studentId, String taskId) {
        Bundle args = new Bundle();
        args.putString( "studentId", studentId );
        args.putString( "taskId", taskId );
        AxisFragment fragment = new AxisFragment();
        fragment.setArguments( args );
        return fragment;
    }

}
